|  |  | @@ -16,7 +16,9 @@ module Agents | 
            
            
              | 16 | 16 |   | 
            
            
              | 17 | 17 |        All the default options must exist. For `infantInSeatCount`, `infantInLapCount`, `seniorCount`, and `childCount`, leave them to the default value of `0` if its not necessary. | 
            
            
              | 18 | 18 |   | 
            
            
              | 19 |  | -      Make sure `date` is in this type of date format `YYYY-MO-DAY`. | 
            
            
              |  | 19 | +      Make sure `date` and `return_date` is in this type of date format `YYYY-MM-DAY`. | 
            
            
              |  | 20 | + | 
            
            
              |  | 21 | +      You can choose one way ticket only by setting `roundtrip` to `false`. | 
            
            
              | 20 | 22 |   | 
            
            
              | 21 | 23 |        You can limit the number of `solutions` returned back. The first solution is the lowest priced ticket. | 
            
            
              | 22 | 24 |      MD | 
            
            
            
            
              |  |  | @@ -56,6 +58,8 @@ module Agents | 
            
            
              | 56 | 58 |          'infantInSeatCount' => 0, | 
            
            
              | 57 | 59 |          'infantInLapCount'=> 0, | 
            
            
              | 58 | 60 |          'seniorCount'=> 0, | 
            
            
              |  | 61 | +        'return_date' => '2016-04-18', | 
            
            
              |  | 62 | +        'roundtrip' => true, | 
            
            
              | 59 | 63 |          'solutions'=> 3 | 
            
            
              | 60 | 64 |        } | 
            
            
              | 61 | 65 |      end | 
            
            
            
            
              |  |  | @@ -69,8 +73,10 @@ module Agents | 
            
            
              | 69 | 73 |      form_configurable :infantInSeatCount | 
            
            
              | 70 | 74 |      form_configurable :infantInLapCount | 
            
            
              | 71 | 75 |      form_configurable :seniorCount | 
            
            
              |  | 76 | +    form_configurable :roundtrip, type: :boolean | 
            
            
              |  | 77 | +    form_configurable :return_date, type: :string | 
            
            
              | 72 | 78 |      form_configurable :solutions | 
            
            
              | 73 |  | - | 
            
            
              |  | 79 | +     | 
            
            
              | 74 | 80 |      def validate_options | 
            
            
              | 75 | 81 |        errors.add(:base, "You need a qpx api key") unless options['qpx_api_key'].present? | 
            
            
              | 76 | 82 |        errors.add(:base, "Adult Count must exist") unless options['adultCount'].present? | 
            
            
            
            
              |  |  | @@ -82,14 +88,26 @@ module Agents | 
            
            
              | 82 | 88 |        errors.add(:base, "Infant In Lap Count") unless options['infantInLapCount'].present? | 
            
            
              | 83 | 89 |        errors.add(:base, "Senior Count must exist") unless options['seniorCount'].present? | 
            
            
              | 84 | 90 |        errors.add(:base, "Solutions must exist") unless options['solutions'].present? | 
            
            
              |  | 91 | +      errors.add(:base, "Returned Date must exist") if options["return_date"].blank? && boolify(options['roundtrip']) | 
            
            
              | 85 | 92 |      end | 
            
            
              | 86 | 93 |   | 
            
            
              | 87 | 94 |      def working? | 
            
            
              | 88 | 95 |        !recent_error_logs? | 
            
            
              | 89 | 96 |      end | 
            
            
              | 90 | 97 |   | 
            
            
              |  | 98 | +    def round_trip? | 
            
            
              |  | 99 | +      boolify(interpolated['roundtrip']) | 
            
            
              |  | 100 | +    end | 
            
            
              |  | 101 | + | 
            
            
              |  | 102 | +    def post_params | 
            
            
              |  | 103 | +      if round_trip? | 
            
            
              |  | 104 | +        post_params = {:request=>{:passengers=>{:kind=>"qpxexpress#passengerCounts", :adultCount=> interpolated["adultCount"], :childCount=> interpolated["childCount"], :infantInLapCount=>interpolated["infantInLapCount"], :infantInSeatCount=>interpolated['infantInSeatCount'], :seniorCount=>interpolated["seniorCount"]}, :slice=>[ {:origin=> interpolated["origin"].to_s , :destination=> interpolated["destination"].to_s , :date=> interpolated["date"].to_s }, {:origin=> interpolated["destination"].to_s , :destination=> interpolated["origin"].to_s , :date=> interpolated["return_date"].to_s } ], :solutions=> interpolated["solutions"]}} | 
            
            
              |  | 105 | +      else | 
            
            
              |  | 106 | +        post_params = {:request=>{:passengers=>{:kind=>"qpxexpress#passengerCounts", :adultCount=> interpolated["adultCount"], :childCount=> interpolated["childCount"], :infantInLapCount=>interpolated["infantInLapCount"], :infantInSeatCount=>interpolated['infantInSeatCount'], :seniorCount=>interpolated["seniorCount"]}, :slice=>[{:kind=>"qpxexpress#sliceInput", :origin=> interpolated["origin"].to_s , :destination=> interpolated["destination"].to_s , :date=> interpolated["date"].to_s }], :solutions=> interpolated["solutions"]}} | 
            
            
              |  | 107 | +      end | 
            
            
              |  | 108 | +    end | 
            
            
              |  | 109 | + | 
            
            
              | 91 | 110 |      def check | 
            
            
              | 92 |  | -      post_params = {:request=>{:passengers=>{:kind=>"qpxexpress#passengerCounts", :adultCount=> interpolated["adultCount"], :childCount=> interpolated["childCount"], :infantInLapCount=>interpolated["infantInLapCount"], :infantInSeatCount=>interpolated['infantInSeatCount'], :seniorCount=>interpolated["seniorCount"]}, :slice=>[{:kind=>"qpxexpress#sliceInput", :origin=> interpolated["origin"].to_s , :destination=> interpolated["destination"].to_s , :date=> interpolated["date"].to_s }], :solutions=> interpolated["solutions"]}} | 
            
            
              | 93 | 111 |        body = JSON.generate(post_params) | 
            
            
              | 94 | 112 |        request = HTTParty.post(event_url, :body => body, :headers => {"Content-Type" => "application/json"}) | 
            
            
              | 95 | 113 |        events = JSON.parse request.body |